package com.dyna.mapper;

import com.dyna.core.LambdaQueryWrapperX;
import com.dyna.foundation.domain.entity.SysDept;
import com.dyna.foundation.domain.req.SysDeptListReq;
import com.dyna.foundation.domain.req.SysDeptPageReq;
import com.dyna.foundation.domain.resp.SysDeptPageResp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;

/**
* @author zhoucaiwang
*/

@Mapper
public interface SysDeptMapper extends BaseMapperX<SysDept> {

    /**
     * 部门列表分页查询
     * @param req 查询参数
     */
    List<SysDeptPageResp> selectPageList(@Param("req") SysDeptPageReq req);

    default List<SysDept> selectList(SysDeptListReq reqVO) {
        return selectList(new LambdaQueryWrapperX<SysDept>()
                .likeIfPresent(SysDept::getDeptName, reqVO.getName())
                .eqIfPresent(SysDept::getStatus, reqVO.getStatus()));
    }

    default List<SysDept> selectListByIds(Collection<Long> ids) {
        return selectList(SysDept::getDeptId, ids);
    }

    default List<SysDept> selectListByParentId(Collection<Long> parentIds) {
        return selectList(SysDept::getParentId, parentIds);
    }

    default SysDept selectByParentIdAndName(Long parentId, String name) {
        return selectOne(SysDept::getParentId, parentId, SysDept::getDeptName, name);
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(SysDept::getParentId, parentId);
    }

}




